package com.dao;


import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.beans.Exercice;
import com.utils.HibernateUtils;
import java.util.List;

public class ExerciceDao {

	public ExerciceDao() {
		super();
	}
	public void addExercice(Exercice exercice) {

		Session session = HibernateUtils.currentSession();

		Transaction tx = session.beginTransaction();

		session.save(exercice);

		tx.commit();
		HibernateUtils.closeSession();

	}

	public Exercice findExercice(int exoEtat) {

		Session session = HibernateUtils.currentSession();

		Query query = session.createQuery("from Excercice where excerciceEtat='"
				+ exoEtat+ "'");
		List<Exercice> listExcercice = query.list();

		HibernateUtils.closeSession();

		return listExcercice.get(0);

	}

	public void updateExcercice(Exercice exercice) {

		Session session = HibernateUtils.currentSession();

		Transaction tx = session.beginTransaction();

		session.update(exercice);

		tx.commit();
		HibernateUtils.closeSession();

	}
	public void deleteExcercice(Exercice exercice) {

		Session session = HibernateUtils.currentSession();

		Transaction tx = session.beginTransaction();

		session.delete(exercice);

		tx.commit();
		HibernateUtils.closeSession();

	}

	
	
}
